# from nonebot import on_regex
# from nonebot.typing import T_State
# from nonebot.adapters.onebot.v11 import GroupMessageEvent, Bot, Message

# Test = on_regex(pattern=r'^qwq$',priority=1)


# @Test.handle()
# async def Test_send(bot: Bot, event: GroupMessageEvent, state: T_State):
#     msg = "qwq"
#     await Test.finish(message=Message(msg))

# --------------------


# from nonebot import on_message
# from nonebot.adapters.onebot.v11 import GroupMessageEvent, Bot, Message
# from nonebot.rule import to_me, regex, Rule
# import json

# # 自定义规则函数
# def not_specified_qq(event: GroupMessageEvent) -> bool:
#     return event.get_user_id() != "2164357233"

# # 使用 Rule 结合正则表达式和自定义规则
# Test_qwq = on_message(
#     rule=regex(r'(?i)qwq') & Rule(not_specified_qq),
#     priority=1,
#     block=False  # 如果希望这个处理器处理完后不再传递给其他处理器，可以设置为 True
# )

# @Test_qwq.handle()
# async def qwq_detect(bot: Bot, event: GroupMessageEvent):
    
#     # await Test_qwq.finish(
#     #     message=Message(f"qwq! \n 【debug】 event: GroupMessageEvent = {event.get_event_description()}")
#     # )
        
#     # 方法1：直接访问属性
#     detailed_info = (
#         f"时间: {event.time}\n"
#         f"消息ID: {event.message_id}\n"
#         f"用户ID: {event.user_id}\n"
#         f"群ID: {event.group_id}\n"
#         f"消息内容: {event.raw_message}\n"
#         f"更多详情: {event.dict()}"
#     )

#     # 方法2：JSON序列化（如果需要完整信息）
#     event_json = json.dumps(event.dict(), ensure_ascii=False, indent=4)

#     await Test_qwq.finish(
#         message=Message(
#             f"qwq!"
#             # + f" \n 【debug】 detailed_into = \n{detailed_info}"
#         )
#         # 或者使用 JSON 序列化的方式：
#         # message=Message(f"qwq! \n 【debug】\n{event_json}")
#     )
    
# ---------------------
    
# import re
# from nonebot import on_message
# from nonebot.adapters.onebot.v11 import GroupMessageEvent, Bot, Message
# from nonebot.rule import Rule

# # 自定义规则函数
# def not_specified_qq(event: GroupMessageEvent) -> bool:
#     return event.get_user_id() != "3989128595"

# # 定义一个新的规则来检查消息中的文本部分是否包含 'qwq'
# # def contains_qwq_in_text(event: GroupMessageEvent) -> bool:
# #     for segment in event.message:
# #         if segment.type == 'text' and re.search(r'(?i)qwq', segment.data.get('text', '')):
# #             return True
# #     return False

# def msg_equals_qwq(event: GroupMessageEvent) -> bool:
#     if len(event.message) != 1:
#         return False
#     segment = event.message[0]
#     return segment.type == "text" and segment.data.get('text', '') == "qwq"

# # 使用 Rule 结合自定义规则
# Test_qwq = on_message(
#     # rule=Rule(not_specified_qq, msg_equals_qwq),
#     rule=Rule(msg_equals_qwq),
#     # priority=1,
#     block=False  # 如果希望这个处理器处理完后不再传递给其他处理器，可以设置为 True
# )

# @Test_qwq.handle()
# async def qwq_detect(bot: Bot, event: GroupMessageEvent):
#     if event.group_id == 687304465:
#         return
#     print("qwq!")
#     await Test_qwq.finish(
#         # message=Message(f"qwq!")
#         message=Message(f"qwq! \n e = {event.group_id},  type(e.groupid) = {type(event.group_id)}")
#     )


# ----------------------

import re
from nonebot import on_message
from nonebot.adapters.onebot.v11 import GroupMessageEvent, Bot, Message
from nonebot.rule import Rule

# 自定义规则函数
def not_specified_qq(event: GroupMessageEvent) -> bool:
    return event.get_user_id() != "3989128595"

def msg_equals_qwq(event: GroupMessageEvent) -> bool:
    if len(event.message) != 1:
        return False
    segment = event.message[0]
    return segment.type == "text" and segment.data.get('text', '') == "qwq"



# 使用 Rule 结合自定义规则
Test_qwq = on_message(
    # rule=Rule(not_specified_qq, msg_equals_qwq),
    rule=Rule(msg_equals_qwq),
    priority=1,
    # permission=EVERYONE,
    block=False  # 如果希望这个处理器处理完后不再传递给其他处理器，可以设置为 True
)

@Test_qwq.handle()
async def qwq_detect(bot: Bot, event: GroupMessageEvent):
    if event.group_id == 687304465:
        return
    print("qwq!")
    await Test_qwq.finish(
        message=Message(f"qwq!")
        # message=Message(f"qwq! \n e = {event.group_id},  type(e.groupid) = {type(event.group_id)}")
    )
